<template>
  <div id='number'>
      <div class="inleft div" @click="substrict">-</div>
      <div class="incenter div" v-text="count"></div>
      <div class="inright div" @click="add">+</div>
  </div>
</template>
<script>
import {Toast} from "mint-ui";
export default {
    props:['repertory1'], //用来接收父组件传入过来的数据
    data () {
        return {
            count:1 //代表购买的商品数量
        };
    },
    methods:{
      substrict(){
          this.count--;
          //确保最小值为1
          if(this.count<1){
              this.count = 1;
              Toast('亲，宝贝已经不能再少了');
          }
          this.sendmessage();

      },
      add(){
          this.count++;
          if(this.count>this.repertory1){
              this.count = this.repertory1;
              Toast('库存不足');
          }
          this.sendmessage();
      },
      sendmessage(){
          this.$emit('dataobj',this.count);
      }
  }
}
</script>
<style lang="css" scoped>
    #number .div{
        width:38px;
        height:28px;
        border:1px solid #000;
        border-radius:3px;
        text-align:center;
        display:inline-block;
        line-height:28px;
    }
</style>